from pydantic import BaseModel, field_validator

from forward.extend.pydantic.base import BaseSchema
from forward.model.schemas.lucky.activity import ActivitySchema
from forward.model.schemas.lucky.prize import PrizeOutSchema
from forward.utils.tools import ToolsUtil


class ActivityDetailInSchema(BaseModel):
    activity_id: int
    code: str | None = None
    model_config = {
        "alias_generator": ToolsUtil.to_lower_camel,
        "populate_by_name": True,
    }


class ActivityListInSchema(BaseSchema):
    title: str | None = None
    page_num: int = 1
    page_size: int = 20


class ActivityDrawNumInSchema(BaseSchema):
    activity_id: int
    code: str | None = None


class ActivityCheckDrawEligibleInSchema(BaseSchema):
    activity_id: int
    code: str | None = None


class ActivityPrizeSchema(BaseSchema):
    # id: int | None = None
    prize_id: int
    prize_index: int
    activity_id: int
    num: int | None = None
    remain_num: int | None = None
    prize_level_id: str | None = None
    probability: float | None = None


class ActivityPrizeDetailOutSchema(ActivityPrizeSchema):
    id: int
    prize: PrizeOutSchema
    prize_level_text: str | None = None


class ActivityDetailOutSchema(ActivitySchema):
    merchant: str | None = None
    date_limit: str | None = None
    status_text: str | None = None
    quota_text: str | None = None  # 活动名额 样式：80/100
    model_config = {
        "alias_generator": ToolsUtil.to_lower_camel,
        "populate_by_name": True,
    }


class ActivityOrderAddSchema(BaseSchema):
    contact_name: str | None = None
    contact_phone: str | None = None
    contact_address: str | None = None
    prize: str | None = None
    prize_id: int | None = None
    user_id: int | None = None
    merchant: str | None = None
    activity_id: int | None = None
    activity: str | None = None
    status: int | None = None
    code: str | None = None
    remark: str | None = None
    prize_level_id: int | None = None
    prize_level: str | None = None


class ActivityPrizeLevelOutSchema(BaseSchema):
    id: int
    prize_level_id: int | None = None
    prize_level: str | None = None

    @field_validator("prize_level", mode="before")
    def prize_level_id_to_str(cls, v):
        if v is None:
            if v == 0:
                return "谢谢参与"
            elif v == 1:
                return "一等奖"
            elif v == 2:
                return "二等奖"
            elif v == 3:
                return "三等奖"
            elif v == 4:
                return "四等奖"
            elif v == 5:
                return "五等奖"
            elif v == 6:
                return "六等奖"
            elif v == 7:
                return "七等奖"
            elif v == 8:
                return "八等奖"
            elif v == 9:
                return "九等奖"
        return str(v)
